package roborally.model.filters;
import roborally.model.*;
import java.util.*;

/**
 * A superclass for element filters.
 * Every subclass of an ElementFilter selects certain elements out of the given set according to a criterium, and returns the set of the selected elements.
 */
public abstract class ElementFilter {
	/**
	 * A method that selects elements out of a given set by invoking validate(element), a method implemented in every subclass of ElementFilter that evaluates the element by its criterea.
	 * @param 	elements
	 * 			A set of elements to be filtered.
	 * @return A set of the elements in which each element evaluated to True when invoking validate(element) on them.
	 */
	public Set<Element> filterElements(Set<Element> elements){
		Set<Element> filteredElements = new HashSet<Element>();
		for(Element element : elements){
			if(validate(element))
				filteredElements.add(element);
		}
		return filteredElements;
	}
	/**
	 * Evaluates an element, returning true if the element fits the criterium of the ElementFilter.
	 */
	public abstract boolean validate(Element element);
}
